package ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.util.ArrayList;
import java.util.Date;

import javax.swing.JLabel;
import javax.swing.JPanel;

import model.Message;
import model.MessageType;
import model.Renter;
import model.RenterStatus;
import ui.ItemList;
import control.CtrRenter;

public class MessagePanel extends ItemList{

	private CtrRenter r;
	private ArrayList<Message> messages;
	public MessagePanel(String name, int sizePctY) {
		
		super(name, sizePctY);
		r = new CtrRenter();
		messages = new ArrayList<Message>();
		messages.add(new Message (new Date(),"New application", "Simon Adnersen applied for waiting list", MessageType.APPLICATION));
		messages.add(new Message(new Date(),"Apartment #3: Washing mashine", "Washing mashing is broken", MessageType.COMPLAINT));
		messages.add(new Message(new Date(), "Unfinished tasks", "You have 2 unfinished tasks needing rescheduling", MessageType.UNSOLVEDTASK));

		for(Message m: messages)
		{
			newPanel(m);
		}

	}

	@Override
	protected void setPanels(JPanel p, Object o){
		Message m = (Message) o;
		Color bgColor = Color.ORANGE;
		MessageButtons b = new MessageButtons(MessageType.UNDEFINED);
		String sender = "";
		
		switch(m.getType())
		{
			case SYSTEM:
				bgColor= Color.LIGHT_GRAY;
				b=new MessageButtons(MessageType.SYSTEM);
				//b.setT(MessageType.SYSTEM);
				sender = "System";
				break;
			case UNSOLVEDTASK:
				bgColor= Color.LIGHT_GRAY;
				b=new MessageButtons(MessageType.UNSOLVEDTASK);
				//b.setT(MessageType.UNSOLVEDTASK);
				sender = "System";
				break;
			case EMPTYWAITINGLIST:
				bgColor= Color.LIGHT_GRAY;
				b=new MessageButtons(MessageType.EMPTYWAITINGLIST);
				//b.setT(MessageType.EMPTYWAITINGLIST);
				sender = "System";
				break;
			case APPLICATION:
				bgColor= Color.GREEN;
				b=new MessageButtons(MessageType.APPLICATION);
				//b.setT(MessageType.APPLICATION);
				sender = "New renter";
				break;
			case CUSTOM:
				bgColor = Color.YELLOW;
				b=new MessageButtons(MessageType.CUSTOM);
				//b.setT(MessageType.CUSTOM);
				sender = "User";
				break;
			case COMPLAINT: 
				bgColor= Color.RED;
				b=new MessageButtons(MessageType.COMPLAINT);
				//b.setT(MessageType.COMPLAINT);
				sender = "Renter";
				break;
			case UNDEFINED:
				b.setT(MessageType.UNDEFINED);
				//bgColor = Color.WHITE;
				sender = "Unknown";
				break;
		}
		
		Font font = new Font("Segoe UI Black", Font.BOLD,20);
		Font font2 = new Font("Segoe UI Black", Font.BOLD,12);
		
		JLabel label1 = new JLabel(m.getTitle());
		label1.setFont(font);
		
		JLabel label2 = new JLabel("<html>"+m.getComment()+"<br>Created on: "+m.getCreated()+"<br>Message sent by: "+sender+"</html>");
		label2.setFont(font2);
		
		p.setBackground(bgColor);
		p.add(label1,BorderLayout.CENTER);
        p.add(b,BorderLayout.LINE_END);
        p.add(label2,BorderLayout.PAGE_END);
        
	}
}